<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require dirname(__FILE__).'/pc_controller.php';

class Api_rental extends PC_controller {

    public function __construct(){
        parent::__construct();
        $this->load->model('Customermodel','m_customer');
        $this->load->model('Bannermodel','m_banner');
        $this->load->model('Newsmodel','m_news');
        $this->load->model('Apilogmodel','m_api_log');
        $this->load->model('Smsmodel','m_sms');

        // header('Access-Control-Allow-Origin:*');
    }

    public function __destruct() {
      // $this->session->unset_userdata($this->_action);
      $customer = $this->session->userdata('lenovo_rental_customer');
      $info = $this->input->post();
      $result = $this->response->getResult();
      unset($info['customer_password']);
      unset($result['items']);
      @$this->m_api_log->createApiLog(array(
          'ip_address' => $this->input->ip_address(),
          'customer_id' => empty($customer) ? 0 :  $customer['customer_id'],
          'request_uri' => $_SERVER['REQUEST_URI'],
          'post_data' => json_encode($info,JSON_UNESCAPED_UNICODE),
          'result_data' => json_encode($result,JSON_UNESCAPED_UNICODE),
          'api_log_time_create' => NOW,
          'ua' => empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'],
          // 'terminal' => TERMINAL_WEIXIN,
      ));

      $this->db->close();
  }

    public function index(){

    }

    public function getActiveBannerList() {
      $list = $this->m_banner->getBannerListSection(array(
        'where' => array(
          'banner_status' => STATUS_ACTIVE,
        ),
        'nocount' => true,
      ));

      foreach ($list as $k => $r) {
        $list[$k]['banner_image'] = empty($r['banner_image']) ? '' : UPLOAD_URL_ORIGIN.$r['banner_image'];
      }

      $this->response->setSuccess();
      $this->response->setItems($list);
      $this->response->responseExit();
    }

    public function getHomeNews() {
      $news = $this->m_news->getHomeNews();

      if(!empty($news)) {
        $news['news_image'] = empty($news['news_image']) ? '' : UPLOAD_URL_ORIGIN.$news['news_image'];
      }

      $this->response->setSuccess();
      $this->response->setAddon($news);
      $this->response->responseExit();
    }

    public function getActiveNewsList() {
      $this->validate->setRule('content','string');
      $this->validate->setRule('content','notnull', false);
      $this->validate->setRule('content','optional', true);
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();

      if(!empty($info['content'])) {
        $list = $this->m_news->getSearchNewsList($info['content']);
      } else {
        $list = $this->m_news->getNewsListSection(array(
          'where' => array(
            'news_status' => STATUS_ACTIVE,
          ),
          'nocount' => true,
        ));
      }

      foreach ($list as $k => $r) {
        $list[$k]['news_image'] = empty($r['news_image']) ? '' : UPLOAD_URL_ORIGIN.$r['news_image'];
      }

      $this->response->setSuccess();
      $this->response->setItems($list);
      $this->response->responseExit();
    }

    public function getActiveNews() {
      $this->validate->setRule('news_id','integer');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();

      $news = $this->m_news->getNews($info['news_id'],true,true);
      if(!empty($news)) {
        $news['news_image'] = empty($news['news_image']) ? '' : UPLOAD_URL_ORIGIN.$news['news_image'];
      }

      $this->response->setSuccess();
      $this->response->setAddon($news);
      $this->response->responseExit();
    }

    private function _getRandomCode() {
      // $code = uniqid();
      $code = '';
      $str ='1234567890';
      $len = strlen($str);
      for($i=0;$i<4;$i++) {
        $code = $str[rand()%$len].$code;
      }
      return $code;
    }

    private function _checkPhone($phone) {
      $matches = array();
      return preg_match('/^1[0-9]{10}$/', $phone, $matches);
    }

    public function getRegisterCode() {
      $this->validate->setRule('customer_phone','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();

      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }

      $customer = $this->m_customer->getCustomerByPhone($info['customer_phone']);
      if(!empty($customer)) {
        $this->response->setDetail('该手机号已注册!');
        $this->response->responseExit();
      }

      $time_code = intval($this->session->userdata('lenovo_rental_register_'.$info['customer_phone'].'_time'));

      if(time() - $time_code < 60) {
        $this->response->setDetail('请在一分钟后再请求!');
        $this->response->responseExit();
      }

      $code = $this->_getRandomCode();
      if(ONLINE) {
        $sms_content = '您的注册验证码为'.$code.',有效期10分钟【联想租赁】';
        $result = $this->m_sms->sendSms($info['customer_phone'],$sms_content,'lenovo_rental');
        if($result != 1) {
            $this->response->setDetail('发送验证码错误['.$result.']!');
            $this->response->responseExit();
        }
      }

      $this->session->set_userdata('lenovo_rental_register_'.$info['customer_phone'],$code);
      $this->session->set_userdata('lenovo_rental_register_'.$info['customer_phone'].'_count',5);
      $this->session->set_userdata('lenovo_rental_register_'.$info['customer_phone'].'_time',time());

      $this->response->setSuccess();
      if(!ONLINE) $this->response->setAddon(array('code' => $code));
      $this->response->responseExit();
    }

    public function register() {
      $this->validate->setRule('customer_phone','string');
      $this->validate->setRule('code','string');
      $this->validate->setRule('customer_password','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();
      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }
      if(strlen($info['customer_password']) < 6 || strlen($info['customer_password']) > 16) {
        $this->response->setDetail('密码需要在6到16位之间!');
        $this->response->responseExit();
      }

      $md5_code = $this->session->userdata('lenovo_rental_register_'.$info['customer_phone']);
      $count_code = intval($this->session->userdata('lenovo_rental_register_'.$info['customer_phone'].'_count'));
      $time_code = intval($this->session->userdata('lenovo_rental_register_'.$info['customer_phone'].'_time'));

      if(empty($md5_code)) {
        $this->response->setDetail('该手机号未获取验证码!');
        $this->response->responseExit();
      }

      if(time() - $time_code > 10*60) {
        $this->response->setDetail('已过时，请重新请求验证码!');
        $this->response->responseExit();
      }
      if($count_code < 0) {
        $this->response->setDetail('错误超过5次，请重新获取验证码!');
        $this->response->responseExit();
      }
      $this->session->set_userdata('lenovo_rental_register_'.$info['customer_phone'].'_count',--$count_code);
      if($md5_code != $info['code']) {
        $this->response->setDetail('输入验证码错误!您还有'.$count_code.'次输入机会!');
        $this->response->responseExit();
      }

      $customer = $this->m_customer->getCustomerByPhone($info['customer_phone']);
      if(!empty($customer)) {
        $this->response->setDetail('该手机号已注册!');
        $this->response->responseExit();
      }
      unset($info['code']);
      $info['customer_password'] = md5($info['customer_password'].SALT);
      $info['customer_time_create'] = NOW;
      $info['customer_status'] = STATUS_PENDING;

      $customer_id = $this->m_customer->createCustomer($info);
      if($customer_id == 0) {
        $this->response->setDetail('注册失败，请重试!');
        $this->response->responseExit();
      }


      // $this->session->unset_userdata('lenovo_rental_register_'.$info['customer_phone']);
      // $this->session->unset_userdata('lenovo_rental_register_'.$info['customer_phone'].'_count');
      // $this->session->unset_userdata('lenovo_rental_register_'.$info['customer_phone'].'_time');

      $this->response->setSuccess();
      $this->response->setDetail('注册成功!');
      $this->response->responseExit();
    }

    public function getForgetPasswordCode() {
      $this->validate->setRule('customer_phone','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();
      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }
      $customer = $this->m_customer->getCustomerByPhone($info['customer_phone']);
      if(empty($customer)) {
        $this->response->setDetail('用户不存在!');
        $this->response->responseExit();
      }

      $time_code = intval($this->session->userdata('lenovo_rental_password_'.$info['customer_phone'].'_time'));

      if(time() - $time_code < 60) {
        $this->response->setDetail('请在一分钟后再请求!');
        $this->response->responseExit();
      }

      $code = $this->_getRandomCode();
      if(ONLINE) {
        $sms_content = '您的找回密码验证码为'.$code.',有效期10分钟【联想租赁】';
        $result = $this->m_sms->sendSms($info['customer_phone'],$sms_content,'lenovo_rental');
        if($result != 1) {
            $this->response->setDetail('发送验证码错误['.$result.']!');
            $this->response->responseExit();
        }
      }

      $this->session->set_userdata('lenovo_rental_forget_password_'.$info['customer_phone'],$code);
      $this->session->set_userdata('lenovo_rental_forget_password_'.$info['customer_phone'].'_count',5);
      $this->session->set_userdata('lenovo_rental_forget_password_'.$info['customer_phone'].'_time',time());

      $this->response->setSuccess();
      if(!ONLINE) $this->response->setAddon(array('code' => $code));
      $this->response->responseExit();
    }

    public function setForgetPassword() {
      $this->validate->setRule('customer_phone','string');
      $this->validate->setRule('code','string');
      $this->validate->setRule('customer_password','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();
      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }
      $customer = $this->m_customer->getCustomerByPhone($info['customer_phone']);
      if(empty($customer)) {
        $this->response->setDetail('用户不存在!');
        $this->response->responseExit();
      }

      if(strlen($info['customer_password']) < 6 || strlen($info['customer_password']) > 16) {
        $this->response->setDetail('密码需要在6到16位之间!');
        $this->response->responseExit();
      }

      $md5_code = $this->session->userdata('lenovo_rental_forget_password_'.$info['customer_phone']);
      $count_code = intval($this->session->userdata('lenovo_rental_forget_password_'.$info['customer_phone'].'_count'));
      $time_code = intval($this->session->userdata('lenovo_rental_forget_password_'.$info['customer_phone'].'_time'));

      if(empty($md5_code)) {
        $this->response->setDetail('该手机号未获取验证码!');
        $this->response->responseExit();
      }

      if(time() - $time_code > 10*60) {
        $this->response->setDetail('已过时，请重新请求验证码!');
        $this->response->responseExit();
      }
      if($count_code < 0) {
        $this->response->setDetail('错误超过5次，请重新获取验证码!');
        $this->response->responseExit();
      }
      $this->session->set_userdata('lenovo_rental_forget_password_'.$info['customer_phone'].'_count',--$count_code);
      if($md5_code != $info['code']) {
        $this->response->setDetail('输入验证码错误!您还有'.$count_code.'次输入机会!');
        $this->response->responseExit();
      }

      $this->m_customer->editCustomer(array(
        'customer_id' => $customer['customer_id'],
        'customer_password' => md5($info['customer_password'].SALT),
      ));

      // $this->session->unset_userdata('lenovo_rental_forget_password_'.$info['customer_phone']);
      // $this->session->unset_userdata('lenovo_rental_forget_password_'.$info['customer_phone'].'_count');
      // $this->session->unset_userdata('lenovo_rental_forget_password_'.$info['customer_phone'].'_time');

      $this->response->setSuccess();
      $this->response->setDetail('修改成功!');
      $this->response->responseExit();
    }

    public function login() {
      $this->validate->setRule('customer_phone','string');
      $this->validate->setRule('customer_password','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();
      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }
      $customer = $this->m_customer->getCustomerByPhone($info['customer_phone']);
      if(empty($customer)) {
        $this->response->setDetail('用户不存在!');
        $this->response->responseExit();
      }
      if(md5($info['customer_password'].SALT) != $customer['customer_password']) {
        $this->response->setDetail('密码错误!');
        $this->response->responseExit();
      }
      $customer['customer_time_lastlogin'] = NOW;
      $this->m_customer->editCustomer(array(
        'customer_id' => $customer['customer_id'],
        'customer_time_lastlogin' => NOW,
      ));

      unset($customer['customer_password']);
      $this->session->set_userdata('lenovo_rental_customer',$customer);

      $this->response->setSuccess();
      $this->response->setDetail('登录成功!');
      $this->response->setAddon(array(
        'customer' => $customer,
      ));
      $this->response->responseExit();
    }

    private function _checkLogin($check = true) {
      $customer = $this->session->userdata('lenovo_rental_customer');
      if($check && empty($customer)) {
        $this->response->setDetail('还未登录或登录信息已过期!');
        $this->response->responseExit();
      }
      return $customer;
    }

    public function getMyInfo() {
      $customer = $this->_checkLogin();
      $this->response->setSuccess();
      $this->response->setDetail('获取个人信息成功!');
      $this->response->setAddon(array(
        'customer' => $customer,
      ));
      $this->response->responseExit();
    }

    public function editMyInfo() {
      $customer = $this->_checkLogin();

      $this->validate->setRule('customer_name','string');
      $this->validate->setRule('customer_companey','string');
      $this->validate->setRule('customer_email','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();

      $info['customer_id'] = $customer['customer_id'];
      $this->m_customer->editCustomer($info);

      $customer = $this->m_customer->getCustomer($customer['customer_id']);
      unset($customer['customer_password']);
      $this->session->set_userdata('lenovo_rental_customer',$customer);

      $this->response->setSuccess();
      $this->response->setDetail('保存个人信息成功!');
      $this->response->setAddon(array(
        'customer' => $customer,
      ));
      $this->response->responseExit();
    }

    public function getChangePasswordCode() {
      $customer = $this->_checkLogin();

      $this->validate->setRule('customer_phone','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();
      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }
      if($customer['customer_phone'] != $info['customer_phone']) {
        $this->response->setDetail('请输入我的正确的手机号!');
        $this->response->responseExit();
      }

      $time_code = intval($this->session->userdata('lenovo_rental_password_'.$info['customer_phone'].'_time'));

      if(time() - $time_code < 60) {
        $this->response->setDetail('请在一分钟后再请求!');
        $this->response->responseExit();
      }

      $code = $this->_getRandomCode();
      if(ONLINE) {
        $sms_content = '您的修改密码验证码为'.$code.',有效期10分钟【联想租赁】';
        $result = $this->m_sms->sendSms($info['customer_phone'],$sms_content,'lenovo_rental');
        if($result != 1) {
            $this->response->setDetail('发送验证码错误['.$result.']!');
            $this->response->responseExit();
        }
      }

      $this->session->set_userdata('lenovo_rental_password_'.$info['customer_phone'],$code);
      $this->session->set_userdata('lenovo_rental_password_'.$info['customer_phone'].'_count',5);
      $this->session->set_userdata('lenovo_rental_password_'.$info['customer_phone'].'_time',time());

      $this->response->setSuccess();
      if(!ONLINE) $this->response->setAddon(array('code' => $code));
      $this->response->responseExit();
    }

    public function changePassword() {
      $customer = $this->_checkLogin();

      $this->validate->setRule('customer_phone','string');
      $this->validate->setRule('code','string');
      $this->validate->setRule('customer_password','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();
      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }
      if($customer['customer_phone'] != $info['customer_phone']) {
        $this->response->setDetail('请输入我的正确的手机号!');
        $this->response->responseExit();
      }

      if(strlen($info['customer_password']) < 6 || strlen($info['customer_password']) > 16) {
        $this->response->setDetail('密码需要在6到16位之间!');
        $this->response->responseExit();
      }

      $md5_code = $this->session->userdata('lenovo_rental_password_'.$info['customer_phone']);
      $count_code = intval($this->session->userdata('lenovo_rental_password_'.$info['customer_phone'].'_count'));
      $time_code = intval($this->session->userdata('lenovo_rental_password_'.$info['customer_phone'].'_time'));

      if(empty($md5_code)) {
        $this->response->setDetail('该手机号未获取验证码!');
        $this->response->responseExit();
      }

      if(time() - $time_code > 10*60) {
        $this->response->setDetail('已过时，请重新请求验证码!');
        $this->response->responseExit();
      }
      if($count_code < 0) {
        $this->response->setDetail('错误超过5次，请重新获取验证码!');
        $this->response->responseExit();
      }
      $this->session->set_userdata('lenovo_rental_password_'.$info['customer_phone'].'_count',--$count_code);
      if($md5_code != $info['code']) {
        $this->response->setDetail('输入验证码错误!您还有'.$count_code.'次输入机会!');
        $this->response->responseExit();
      }

      $this->m_customer->editCustomer(array(
        'customer_id' => $customer['customer_id'],
        'customer_password' => md5($info['customer_password'].SALT),
      ));

      // $this->session->unset_userdata('lenovo_rental_password_'.$info['customer_phone']);
      // $this->session->unset_userdata('lenovo_rental_password_'.$info['customer_phone'].'_count');
      // $this->session->unset_userdata('lenovo_rental_password_'.$info['customer_phone'].'_time');

      $this->response->setSuccess();
      $this->response->setDetail('修改成功!');
      $this->response->responseExit();
    }


    public function getChangePhoneCode() {
      $customer = $this->_checkLogin();

      $this->validate->setRule('customer_phone','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();
      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }
      $tmp_customer = $this->m_customer->getCustomerByPhone($info['customer_phone']);
      if(!empty($tmp_customer)) {
        $this->response->setDetail('该手机号已注册!');
        $this->response->responseExit();
      }

      $time_code = intval($this->session->userdata('lenovo_rental_phone_'.$info['customer_phone'].'_time'));

      if(time() - $time_code < 60) {
        $this->response->setDetail('请在一分钟后再请求!');
        $this->response->responseExit();
      }

      $code = $this->_getRandomCode();
      if(ONLINE) {
        $sms_content = '您的修改手机号验证码为'.$code.',有效期10分钟【联想租赁】';
        $result = $this->m_sms->sendSms($info['customer_phone'],$sms_content,'lenovo_rental');
        if($result != 1) {
            $this->response->setDetail('发送验证码错误['.$result.']!');
            $this->response->responseExit();
        }
      }

      $this->session->set_userdata('lenovo_rental_phone_'.$info['customer_phone'],$code);
      $this->session->set_userdata('lenovo_rental_phone_'.$info['customer_phone'].'_count',5);
      $this->session->set_userdata('lenovo_rental_phone_'.$info['customer_phone'].'_time',time());

      $this->response->setSuccess();
      if(!ONLINE) $this->response->setAddon(array('code' => $code));
      $this->response->responseExit();
    }

    public function changePhone() {
      $customer = $this->_checkLogin();

      $this->validate->setRule('customer_phone','string');
      $this->validate->setRule('code','string');
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();
      if(!$this->_checkPhone($info['customer_phone'])) {
        $this->response->setDetail('请输入正确的手机号!');
        $this->response->responseExit();
      }
      $md5_code = $this->session->userdata('lenovo_rental_phone_'.$info['customer_phone']);
      $count_code = intval($this->session->userdata('lenovo_rental_phone_'.$info['customer_phone'].'_count'));
      $time_code = intval($this->session->userdata('lenovo_rental_phone_'.$info['customer_phone'].'_time'));

      if(empty($md5_code)) {
        $this->response->setDetail('该手机号未获取验证码!');
        $this->response->responseExit();
      }

      if(time() - $time_code > 10*60) {
        $this->response->setDetail('已过时，请重新请求验证码!');
        $this->response->responseExit();
      }
      if($count_code < 0) {
        $this->response->setDetail('错误超过5次，请重新获取验证码!');
        $this->response->responseExit();
      }
      $this->session->set_userdata('lenovo_rental_phone_'.$info['customer_phone'].'_count',--$count_code);
      if($md5_code != $info['code']) {
        $this->response->setDetail('输入验证码错误!您还有'.$count_code.'次输入机会!');
        $this->response->responseExit();
      }

      $tmp_customer = $this->m_customer->getCustomerByPhone($info['customer_phone']);
      if(!empty($tmp_customer)) {
        $this->response->setDetail('该手机号已注册!');
        $this->response->responseExit();
      }

      $this->m_customer->editCustomer(array(
        'customer_id' => $customer['customer_id'],
        'customer_phone' => $info['customer_phone'],
      ));

      $customer = $this->m_customer->getCustomer($customer['customer_id']);
      unset($customer['customer_password']);
      $this->session->set_userdata('lenovo_rental_customer',$customer);


      // $this->session->unset_userdata('lenovo_rental_phone_'.$info['customer_phone']);
      // $this->session->unset_userdata('lenovo_rental_phone_'.$info['customer_phone'].'_count');
      // $this->session->unset_userdata('lenovo_rental_phone_'.$info['customer_phone'].'_time');

      $this->response->setSuccess();
      $this->response->setDetail('修改成功!');
      $this->response->responseExit();
    }

    public function makeRental() {
        // $this->validate->setRule('customer_rental_phone','string');
        $this->validate->setRule('customer_rental_name','string');
        $this->validate->setRule('customer_rental_companey','string');
        $this->validate->setRule('customer_rental_position','string');
        $this->validate->setRule('customer_rental_email','string');
        $this->validate->setRule('customer_rental_contract','string');
        $this->validate->setRule('customer_rental_device_type','integer');
        $this->validate->setRule('customer_rental_deadline','string');
        $this->validate->setRule('customer_rental_money','string');
        if(!$this->validate->run($this->input->post())){
          $this->response->setDetail($this->validate->getMessage());
          $this->response->responseExit();
        }
        $info = $this->validate->getResult();

        $customer = $this->_checkLogin(false);
        if(!empty($customer)) {
          $info['customer_id'] = $customer['customer_id'];
        }
        $info['customer_rental_time_create'] = NOW;

        $this->m_customer->createCustomerRental($info);

        $this->response->setSuccess();
        $this->response->setDetail('提交成功!');
        $this->response->responseExit();
    }

    public function getRentalList() {
      $customer = $this->_checkLogin(false);
      if(empty($customer)) {
        $this->response->setSuccess();
        $this->response->responseExit();
      }

      $list = $this->m_customer->getCustomerRentalListByCustomerId($customer['customer_id']);

      $this->response->setSuccess();
      $this->response->setItems($list);
      $this->response->responseExit();
    }

    public function search() {
      $this->validate->setRule('content','string');
      $this->validate->setRule('content','notnull', false);
      if(!$this->validate->run($this->input->post())){
        $this->response->setDetail($this->validate->getMessage());
        $this->response->responseExit();
      }
      $info = $this->validate->getResult();

      $list = $this->m_news->getSearchNewsList($info['content']);

      foreach ($list as $k => $r) {
        $list[$k]['news_image'] = empty($r['news_image']) ? '' : UPLOAD_URL_ORIGIN.$r['news_image'];
      }

      $this->response->setSuccess();
      $this->response->setItems($list);
      $this->response->responseExit();
    }

    public function logout() {
      $this->session->unset_userdata('lenovo_rental_customer');

      $this->response->setSuccess();
      $this->response->responseExit();
    }
}
/* End of file api_log.php */
/* Location: ./application/controllers/customer_rental.php */
